<%--
  Created by IntelliJ IDEA.
  User: 12700
  Date: 2025/9/1
  Time: 19:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>注册页</title>
    <link rel="stylesheet" href="../../css/login.css">
    <script type="text/javascript" src="../../js/jquery-1.8.3.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("[value='注册']").click(function () {
                var username=$("#username").val();
                var password=$("#password").val();
                var roles=$("[name='角色']").val();
                if(roles==1){
                    var roles="用户";
                }else if(roles==2){
                    var roles="物流员";
                }else if(roles==3){
                    var roles="管理员";
                }else{
                    alert("请选择注册角色！")
                    window.location.href="register.jsp";
                }
                var password1=$("#password1").val();
                        if(password==password1){
                            $.get("../../login/register",{"username":username,"password":password,"roles":roles},function (b) {
                                JSON.stringify(b);
                                if(b){
                                    alert("注册成功！");
                                    window.location.href="../../index.jsp";
                                }else {
                                    alert("用户名已被注册或用户名与密码为空!");
                                    window.location.href="register.jsp";
                                };
                            });
                        }else{
                            alert("两次输入的密码不一样!");
                            window.location.href="register.jsp";
                        }

            });
        });
    </script>
</head>
<body>
<div class="label">
    <div class="box">
        <div class="box-left">
            <div><img src="../../images/rest.jpeg" alt=""></div>
        </div>
        <div class="box-right">
            <table>
                <tr>
                    <h2>注册</h2>
                </tr>
                <tr>
                    <p>账户:</p>
                    <input type="text" id="username">
                    <p>密码:</p>
                    <input type="text" id="password">
                    <p>确认密码:</p>
                    <input type="text" id="password1">
                    <p>角色:</p>
                    <select name="角色">
                        <option value="-1">请选择</option>
                        <option value="1">用户</option>
                        <option value="2">物流员</option>
                        <option value="3">管理员</option>
                    </select>
                    <input type="button" value="注册">
                    <div><a href="../../index.jsp">已有账户？点此返回登录</a></div>
                </tr>
            </table>
        </div>
    </div>
</div>
</body>
</html>
